<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="__PUBLIC__/css/font.css">
    <link rel="stylesheet" href="__PUBLIC__/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__PUBLIC__/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        em {
            font-size: 16px;
            margin: 0 3px;
            color: red;
            font-weight:bold;
        }
        .hot {
            line-height: 40px;
            border-bottom: 1px dashed #CCC;
            font-size:14px;
        }
        .yuan {
            display:inline-block;
            width: 25px;
            height:25px;
            border-radius: 25px;
            border:1px solid #CCC;
            line-height:25px;
            text-align: center;
            margin-right:10px;
        }
        .total-left {
            width: 45%;
            height: auto;
            overflow: hidden;
            float: left;
        }
        .total-right {
            width: 50%;
            height: auto;
            overflow: hidden;
            float: right;
        }

    </style>
</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="/">首页</a>
        <a href="">销售统计</a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <form method="post" action="" class="layui-form layui-col-md12 x-so">
            <input class="layui-input" placeholder="选择要查看的日期" value="{$start}" name="start" required="required" id="start">
            <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>
    <xblock>
        今日共有订单<em>{:count($data)}</em>笔&nbsp;&nbsp;&nbsp;&nbsp;总金额：￥<em>{$order_total}</em>元
        &nbsp;&nbsp;&nbsp;&nbsp;
        <foreach name="order_pay" item="item">
            {$item.order_pay}支付订单<em>{$item.count}</em>笔&nbsp;&nbsp;&nbsp;&nbsp;
        </foreach>
    </xblock>
    <div class="layui-row">
        <h3 style="font-weight: bold;">{$start}号收益明细</h3>
        <table class="layui-table">
            <foreach name="data" item="item">

                <tr>
                    <td style="text-align: left; background: #01AAED; color: #FFF">订单号：</td>
                    <td style="text-align: left; padding-left: 10px;background: #01AAED; color: #FFF">{$item.order_id}</td>
                </tr>
                <tr>
                    <?php
                        $food = D('OrderDetail as d')
                            ->where(['d.order_id'=>$item['id']])
                            ->join('left join food_food as f on d.food_id=f.id')
                            ->field(['d.id, d.food_id,f.name, d.num, f.price'])

                    ->select();
                    $total = 0;
                    ?>
                    <td style="text-align: left;">菜谱信息：</td>
                    <td style="text-align: left; padding-left: 10px;">
                        <foreach name="food" item="vo">
                            <div>菜谱名称：{$vo.name}&nbsp;&nbsp;&nbsp;&nbsp;价格：￥{$vo['price'] / 100 |number_format=###, 2}&nbsp;&nbsp;&nbsp;&nbsp;数量：{$vo.num}</div>
                            <php>$total += $vo['price'];</php>
                        </foreach>
                    </td>
                </tr>
                <tr>
                    <td style="text-align: left">小计信息：</td>
                    <td style="text-align: left">
                        数量：{$food|count=###}&nbsp;&nbsp;&nbsp;&nbsp;
                        合计：￥{$total / 100 |number_format=###, 2}元&nbsp;&nbsp;&nbsp;&nbsp;
                        折扣：￥{$item.djqmoney}&nbsp;&nbsp;&nbsp;&nbsp;
                        {$item.order_pay}支付：￥<php> $price = $item['sfmoney'] < 1 ? $item['order_total'] : $item['sfmoney']; echo $price; </php>元&nbsp;&nbsp;&nbsp;&nbsp;
                    </td>
                </tr>
            </foreach>
        </table>
        <div class="total-left">
            <h3 style="font-weight: bold;">{$start}号菜谱销量排行榜</h3>
            <hr />
            <foreach name="data" item="item">
                <?php
            $food = D('OrderDetail as d')
                    ->where(['d.order_id'=>$item['id']])
                ->join('left join food_food as f on d.food_id=f.id')
                ->field(['d.id, d.food_id,f.name, d.num, f.price'])
                ->order('num desc')
                ->select();

                $arr[] = $food;
                ?>
            </foreach>
            <php>
                $data = [];
                foreach ($arr as $key => $val) {
                    foreach ($val as $k => $v) {
                        $data[] = $v;
                    }
                }
                usort($data, function($a, $b) {
                    return $a['num'] > $b['num'] ? -1 : 1;
                });
            </php>

            <foreach name="data" item="food" key="k">
                <div class="hot"><span class="yuan">{$k + 1}</span> 菜谱名称：{$food.name}&nbsp;&nbsp;&nbsp;&nbsp;价格：￥{$food['price'] / 100 |number_format=###, 2}&nbsp;&nbsp;&nbsp;&nbsp;数量：{$food.num}</div>
            </foreach>
        </div>

        <div class="total-right">
            <h3 style="font-weight: bold;">{$start}桌子使用率统计</h3>
            <hr />
                <foreach name="table" item="tab">
                <div class="hot"><span class="yuan">{$key + 1}</span>{$tab.isbox} - {$tab.table_name}&nbsp;&nbsp; 使用次数：{$tab.cpl}次</div>
                </foreach>
        </div>
    </div>
</div>
</body>

</html>
<script>
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#start', //指定元素
            max: 0,
        });

    });
</script>